<template>
  <div id="app">
    <h1>根组件--- {{ $store.state.user.name }}</h1>
    <h1>{{ name }}</h1>
    <input type="text">
    <button @click="add">改名</button>
    <add-item></add-item>
    <hr>
    <sub-item></sub-item>
  </div>
</template>

<script>
import AddItem from './components/add-item.vue'
import SubItem from './components/sub-item.vue'
import { mapState } from 'vuex'

export default {
  name: 'app',
  data: function () {
    return {
      
    }
  },
  components: {
    AddItem,
    SubItem
  },
  methods:{
    add(){
      this.$store.commit('user/setName','ww')
    }
  },
  computed:{
    ...mapState('user',['name'])
  }
}
</script>

<style>
#app {
  width: 600px;
  margin: 20px auto;
  border: 3px solid #ccc;
  border-radius: 3px;
  padding: 10px;
}
</style>